home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7678 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  47 lines

  1. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  2. Path: cwi.nl!dik
  3. From: dik@cwi.nl (Dik T. Winter)
  4. Subject: Re: Access carry flag from C
  5. Message-ID: <DnB4xF.5rE@cwi.nl>
  6. Sender: news@cwi.nl (The Daily Dross)
  7. Nntp-Posting-Host: chrysant.cwi.nl
  8. Organization: CWI, Amsterdam
  9. References: <TANMOY.96Feb21081640@qcd.lanl.gov> <312D8414.167E@bazis.nl> <4glk5t$avt@sun001.spd.dsccc.com>
  10. Date: Sun, 25 Feb 1996 01:17:39 GMT
  11.  
  12. Franz Korntner quotes rationale 2.2.4.2.1 and Mike McCarty quotes standard
  13. 5.2.4.2.1 (and I repeat the relevant part of that):
  14.  >                          Their implementation-defined values shall be
  15.  >     equal or greater in magnitude (absolute value) to those shown, with
  16.  >     the same sign.
  17.  
  18. Both conlcude that the actual arithmetic can have larger limits than
  19. those documented in limits.h.  But this does in no way state that the
  20. limits given in limits.h can be less than the actually implemented limits.
  21. It only states that the actually implemented limits can be larger than
  22. the limits given (as an example) in the standard.  By words in other parts
  23. of the standard (as quoted by Tanmoy) it is clear that the limits as
  24. documented in limits.h must be the actual limits.
  25.  
  26. However, exceeding INT_MAX in signed arithmetic results in undefined
  27. behaviour (and may very well result in a representation that would be
  28. larger than the actual value).  For instance on a Cray the C compiler
  29. has two modes of compilation.  The first is with "fast integer arithmetic"
  30. and if done in that mode INT_MAX is defined as 2^46-1, adding 1 to that
  31. value will result in an internal representation of 2^47.  But using that
  32. value in some multiplication will handle it as if 0 was used.  Allowed
  33. because the result is undefined and anything can happen on overflow of
  34. signed ints.  On the other hand the behaviour of unsigned int with respect
  35. to UINT_MAX is well defined.  Adding 1 to UINT_MAX results in 0 (per the
  36. standard).  (And on that same Cray UINT_MAX is defined as 2^64-1
  37. regardless of the mode of compilation used.)
  38.  
  39. So, INT_MAX does not give much guarantee about the actual arithmetic
  40. used; UINT_MAX does.  But only because the result of exceeding INT_MAX
  41. is undefined behaviour.
  42.  
  43. [And for Dan Bernstein: the Cray does not have a carry flag either.]
  44. -- 
  45. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924098
  46. home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/
  47.